﻿Imports System
Imports System.Text.RegularExpressions
Imports System.Web.UI.Page

Public Class Restaurants
    Inherits System.Web.UI.Page

    Private SearchString As String = ""

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request.Params("Tag") = Nothing Or Request.Params("Tag") = "" Then
            RestaurantsDB.SelectCommand = "SELECT * FROM Restaurants"
        Else
            RestaurantsDB.SelectCommand = "SELECT DISTINCT [Menu], [URL], [RestaurantName], [PostCode], [ID], [Photo], [LastReviewDate], [PriceBracket], [Rating] FROM [RestaurantTagView] WHERE ([Tag] = ?)"
        End If

    End Sub



    Public Function HighlightText(ByVal InputTxt As String) As String
        Dim Search_Str As String = tb_Search.Text
        Dim RegExp As Regex = New Regex(Search_Str.Replace(" ", "|").Trim, RegexOptions.IgnoreCase)
        Return RegExp.Replace(InputTxt, New MatchEvaluator(AddressOf ReplaceKeyWords))

    End Function

    Public Function ReplaceKeyWords(ByVal m As Match) As String
        Return ("<span class=highlight>" + m.Value + "</span>")
    End Function

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
        SearchString = tb_Search.Text
    End Sub

    Protected Sub btnClearSearch_Click(ByVal sender As Object, ByVal e As ImageClickEventArgs)
        tb_Search.Text = ""
        SearchString = ""
        GridView1.DataBind()
    End Sub


    Protected Function getRating(ByVal rating As Integer)
        Dim retval As String
        retval = ""
        For i = 1 To rating
            retval = retval + "*"
        Next
        Return retval
    End Function


End Class